//
//  MHSettingCirleInfoViewController.m
//  MiaoCircle
//
//  Created by 许正荣 on 2018/4/17.
//  Copyright © 2018年 acgera. All rights reserved.
//

#import "MHSettingCirleInfoViewController.h"
#import "MHSetCircleInfoViewModel.h"
#import "MHCircleTagView.h"
#import "MHCircleTag.h"
#import "UITextView+Placeholder.h"
#import "MHInfoImagesScrollView.h"
#import "MHPhotoManager.h"
#import "MHCoverModel.h"
#import "MHH5Links.h"
#import "MHWebViewModel.h"
#import "UITextField+MHExtension.h"
#import "MHCircleSetPriceAlertVoew.h"
#import "MHPriceRange.h"
#import "MHLocationViewModel.h"
#import "MHLocationTipsView.h"
#import "MHLocationManager.h"
#import "MHCircleLocationModel.h"
#import "MHLocationManager.h"
@interface MHSettingCirleInfoViewController ()<UITextViewDelegate,UITextViewDelegate>
@property (weak, nonatomic) IBOutlet UILabel *metionLable;
@property (weak, nonatomic) IBOutlet UITextField *circleNameTextFeild;
@property (weak, nonatomic) IBOutlet UIImageView *circleImageView;
@property (nonatomic, readonly, strong) MHSetCircleInfoViewModel *viewModel;
@property(nonatomic, strong) MHCircleTagView *circleTagView;
@property(nonatomic, strong) NSArray *circleModelArray;
//@property (nonatomic, readwrite, strong) UITextView *textView;
@property(nonatomic, strong) MHInfoImagesScrollView *imageScrollView;
@property (weak, nonatomic) IBOutlet UIImageView *info_bg;
@property (weak, nonatomic) IBOutlet UIButton *checkButton;
@property(nonatomic,strong,readwrite) YYLabel *protocolLable;
//@property (weak, nonatomic) IBOutlet UITextField *priceTextField;
@property (weak, nonatomic) IBOutlet UITextView *descTextView;
@property (weak, nonatomic) IBOutlet UILabel *yuanLabel;
@property (weak, nonatomic) IBOutlet UILabel *payLabel;
@property (weak, nonatomic) IBOutlet UIButton *freeCheckBtn;
@property (weak, nonatomic) IBOutlet UIButton *comfirmBtn;
@property(nonatomic, strong) MHPriceRange *range;
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;
@property (weak, nonatomic) IBOutlet UIButton *modifyBtn;
@property (weak, nonatomic) IBOutlet UIView *locationContainer;
@property(nonatomic, strong) NSArray *fullCoverArray;
@property (weak, nonatomic) IBOutlet UILabel *locationLabel;

@end

@implementation MHSettingCirleInfoViewController
@dynamic viewModel;
- (void)viewDidLoad {
    [super viewDidLoad];
    @weakify(self);
    self.view.backgroundColor = MH_MAIN_BACKGROUNDCOLOR_2;
    self.locationLabel.font = MHRegularFont_12;
    self.tipLocation.font = MHRegularFont_12;
    if (self.viewModel.info.identType == MHCircleIdentityTypeGuestMember && !self.viewModel.isCreate) {
        self.navigationItem.rightBarButtonItem = nil;
    }
//    @weakify(self);
    self.info_bg.masksToBounds = YES;
    self.info_bg.contentMode =  UIViewContentModeScaleAspectFill;
    [RACObserve(self.circleImageView, image) subscribeNext:^(UIImage *image) {
        @strongify(self);
        self.info_bg.image = image;
    }];
    if (![self.viewModel.info currentUserIsOwner] && !self.viewModel.isCreate) {
        self.navigationItem.titleView =  createAttriNavTitleLableWhitColor(@"圈子资料", @"仅圈主可设置",MHWhiteTextColor);
    }else
    {
        self.navigationItem.titleView =  createAttriNavTitleLableWhitColor(@"设置圈子资料", @"",MHWhiteTextColor);
    }
    UIBarButtonItem *leftBarItem = [UIBarButtonItem mh_backItemWithTitle:nil imageName: @"icon_back" target:self action:@selector(_back)];
    // 4.这里可以设置导航栏的左右按钮 统一管理方法
    self.navigationItem.leftBarButtonItem = leftBarItem;
    
    //创建圈子
    if (self.viewModel.isCreate) {
        self.navigationItem.title = @"创建圈子";
        self.freeCheckBtn.selected = true;
        self.modifyBtn.hidden = YES;
        self.priceLabel.hidden = YES;
        
    }else
    {
        self.comfirmBtn.selected = (self.viewModel.info.payType == MHCirclPayTypeCharge);
        self.freeCheckBtn.selected = (self.viewModel.info.payType == MHCirclPayTypeFree);
        
         self.modifyBtn.hidden = YES;
        self.priceLabel.hidden = self.viewModel.info.joinPrice <= 0;
        
        
        self.modifyBtn.userInteractionEnabled = false;
        self.comfirmBtn.userInteractionEnabled = false;
        self.freeCheckBtn.userInteractionEnabled = false;
    }

    if (![AXAppDelegate sharedDelegate].isAuthorizationExpired)
    {
        self.payLabel.hidden = YES;
        self.comfirmBtn.hidden = YES;
        self.freeCheckBtn.hidden = YES;
    }
    

    
    self.priceLabel.text = [NSString stringWithFormat:@"%.0f元/年",self.viewModel.info.joinPrice];
    [[self.viewModel.tagViewModel.requestRemoteDataCommand execute:nil] subscribeNext:^(NSArray *circleArray) {
        @strongify(self);
        self.circleModelArray = circleArray;
        dispatch_async(dispatch_get_main_queue(), ^{
           [self maslayoutSubViews];
        });
    }];
    [self masLayoutSubViews];
    self.yuanLabel.font = MHRegularFont_14;
    self.descTextView.placeholder = @"介绍一下你的圈子吧？~(选填)";
    self.descTextView.font = MHRegularFont_14;
    self.descTextView.delegate = self;
    self.checkButton.selected = YES;
    self.payLabel.font = MHRegularFont_12;
    self.priceLabel.font = MHRegularFont_12;
    self.modifyBtn.titleLabel.font = MHRegularFont_12;
    
    self.freeCheckBtn.titleLabel.font = MHRegularFont_12;
     self.comfirmBtn.titleLabel.font = MHRegularFont_12;
    
    __weak __typeof(self)weakSelf = self;
    [self.modifyBtn bk_whenTapped:^{

        [weakSelf comfirmCheckAction:nil];
    }];
    
    self.locationContainer.userInteractionEnabled = (self.viewModel.isCreate || (!self.viewModel.isCreate && [self.viewModel.info currentUserIsOwner]));
    self.locationLabel.text = self.viewModel.info.location.isShowLocation ? ( self.viewModel.info.location.areaName.length ? self.viewModel.info.location.areaName : @"所在位置") : @"所在位置";
    [self.locationContainer bk_whenTapped:^{
        
        if (![MHLocationManager isLocationServiceOpen]) {
            MHLocationTipsView *locationView = [MHLocationTipsView mh_viewFromXib];
            self.zh_popupController = [zhPopupController new];
            //        self.zh_popupController.layoutType = zhPopupLayoutTypeBottom;
            locationView.width = self.view.mh_width * 0.7;
            locationView.layer.cornerRadius = 8.0;
            locationView.masksToBounds = YES;
            [self.zh_popupController presentContentView:locationView];
            //        locationView.settingButton.rac_command = self.viewModel.nextCommand;
            __weak __typeof(self)weakSelf = self;
            [locationView.startLocation bk_whenTapped:^{
                [[MHLocationManager sharedInstance] openLocationSetting];
                [weakSelf.zh_popupController dismiss];
            }];
            [locationView.dissBtn bk_whenTapped:^{
                
                [weakSelf.zh_popupController dismiss];
            }];
        }else
        {
            MHLocationViewModel *locationViewModel = [[MHLocationViewModel alloc] initWithServices:self.viewModel.services params:nil];
            weakSelf.locationViewModel = locationViewModel;
            
            weakSelf.locationViewModel.completeBlock = ^(MHCustomTip *tip) {
                weakSelf.tip = tip;
               
                 [self configLocation:tip];
//                }
            };
            
            
            
            
            
            [weakSelf.viewModel.services pushViewModel:locationViewModel animated:YES];
        }
    }];

    self.circleImageView.contentMode = UIViewContentModeScaleAspectFill;
    self.circleImageView.userInteractionEnabled = YES;
 
    [[self.viewModel.tagViewModel.requestFullCoverCommand execute:nil] subscribeNext:^(NSArray *fullCoverArray) {
        @strongify(self);
        NSMutableArray *covers =  [fullCoverArray mutableCopy];
        MHCoverModel *model = [MHCoverModel new];
        model.fullCoverUrl = @"circle_info_image";
        
        [covers insertObject:model atIndex:0];
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.imageScrollView setCovers:covers];
            self.fullCoverArray = covers;
            int index = (arc4random() % (covers.count - 1)) + 1;;
            MHCoverModel *model = covers[index];
            if (self.viewModel.isCreate) {
                weakSelf.viewModel.info.coverUrl = model.coverUrl;
                weakSelf.viewModel.info.fullCoverUrl = model.fullCoverUrl;
                [self.circleImageView yy_setImageWithURL:[NSURL URLWithString:model.fullCoverUrl] options:nil];
            }
        });
    }];
    [self.circleImageView bk_whenTapped:^{
//        [self.circleNameTextFeild  resignFirstResponder];
        [self.view endEditing:YES];
        self.zh_popupController = [zhPopupController new];
        self.zh_popupController.layoutType = zhPopupLayoutTypeBottom;
        [self.zh_popupController presentContentView:self.imageScrollView];       
    }];
    if (!self.viewModel.isCreate && ![self.viewModel.info currentUserIsOwner]) {
        self.view.userInteractionEnabled = false;
        self.comfirmBtn.hidden = YES;
        self.checkButton.hidden = YES;
        self.protocolLable.hidden = YES;
    }else
    {

    }
    
    if (self.viewModel.isCreate) {
        [[MHLocationManager sharedInstance] startUpdatingLocationWithBlock:^(CLLocation *location) {
            [[MHLocationManager sharedInstance] searhAroundWithLocation:location reslutBlock:^(AMapPOISearchBaseRequest *requst,AMapPOISearchResponse *response) {
                if(response.pois.count > 0)
                {
                    AMapPOI *currentPOI =  response.pois.firstObject;
                    MHCustomTip *tip =  [MHCustomTip createWithAMapPOI:currentPOI];
                    [self configLocation:tip];
                }
                
            }];
        }];
    }
   
}

-(void) configLocation:(MHCustomTip *)tip
{
//    if (!self.viewModel.isCreate) {
//        self.viewModel.info.isShowLocation = YES;
//    }
//    NSDictionary *dic =   @{
//                            @"lon":@(tip.location.longitude),
//                            @"lat":@(tip.location.latitude),
//                            @"address":tip.address,
//                            @"adcode":tip.adcode,
//                            @"citycode":tip.cityCode,
//                            @"areaName":tip.name,
//                            @"district":tip.district,
//                            };
//    self.locationData = [dic yy_modelToJSONString];
    
//    self.locationLabel.text = tip.name;
//    self.viewModel.info.locationData = [tip.circleLocation yy_modelToJSONString];
    
    self.viewModel.info.location = tip.circleLocation;
     self.locationLabel.text = !tip.isShowLocation ? @"所在位置":tip.name;
//    @weakify(self);
//    [RACObserve(self.viewModel.info, location) subscribeNext:^(MHCircleLocationModel *model) {
//        @strongify(self);
//       
//    }];
}

- (void)_back{
        [self.viewModel.services popViewModelAnimated:YES]; //重新创建了
}

- (IBAction)freeCheckAction:(UIButton *)sender {
    sender.selected = true;
    self.comfirmBtn.selected = false;
    self.viewModel.info.payType = MHCirclPayTypeFree;
    
    self.modifyBtn.hidden = true;
    self.priceLabel.hidden = true;
    
}

- (IBAction)comfirmCheckAction:(UIButton *)sender {
    
    
  
    self.comfirmBtn.selected = true;
    self.freeCheckBtn.selected = false;
    self.viewModel.info.payType = MHCirclPayTypeCharge;
    
//    self.modifyBtn.hidden = false;
//    self.priceLabel.hidden = false;
    if (self.viewModel.info.joinPrice > 0) {
        self.modifyBtn.hidden = false;
        self.priceLabel.hidden = false;
    }
    
    
//    self.zh_popupController = [zhPopupController new];
    MHCircleSetPriceAlertVoew *alertView  = [MHCircleSetPriceAlertVoew mh_viewFromXib];
    alertView.width = self.view.width * 0.7;
    alertView.layer.cornerRadius = 6.0;
    alertView.masksToBounds = YES;
    if (self.viewModel.info.joinPrice > 0) {
        alertView.priceTextFeild.text = [NSString stringWithFormat:@"%.0f",self.viewModel.info.joinPrice];
    }
    __weak __typeof(self)weakSelf = self;
    @weakify(self);
    [[[[MHHTTPService sharedInstance] getJoinCirclePriceRange] mh_parsedResults] subscribeNext:^(MHPriceRange *range) {
        @strongify(self);
//        [ fla
        alertView.tipsLabel.text = [NSString stringWithFormat:@"请输入%.0ld～%.0ld之间的金额",(long)range.minPrice,(long)range.maxPrice];
        self.range = range;
        
    }];

    [alertView.cancelBtn bk_whenTapped:^{
        [weakSelf freeCheckAction:weakSelf.freeCheckBtn];
        [weakSelf.zh_popupController dismiss];
        
    }];
//    weakify(alertView);
   
    
    [alertView.sendBtn bk_whenTapped:^{
        [alertView.priceTextFeild resignFirstResponder];
        if (alertView.priceTextFeild.text.length <= 0 || [alertView.priceTextFeild.text integerValue] <= 0) {
            [UIWindow showTips:@"请输入正确的金额"];
            return ;
        }
        
        if ([alertView.priceTextFeild.text integerValue] < (long)self.range.minPrice || [alertView.priceTextFeild.text integerValue] > (long)self.range.maxPrice) {
            [UIWindow showTips:@"请输入合适的价格范围"];
            return ;
        }
        self.modifyBtn.hidden = NO;
        self.priceLabel.hidden = NO;
        self.priceLabel.text = [NSString stringWithFormat:@"%@元/年",alertView.priceTextFeild.text];
        weakSelf.viewModel.info.joinPrice = [alertView.priceTextFeild.text doubleValue];
        [weakSelf.zh_popupController dismiss];
        
    }];
    
//    [atttionView.attionImageView yy_setImageWithURL:[NSURL URLWithString:info.qrCodeUrl] placeholder:MHDefaultAvatar(MHDefaultAvatarTypeSmall)];
    self.zh_popupController = [zhPopupController new];
    [self.zh_popupController presentContentView:alertView];
    [self.zh_popupController setDidDismiss:^(zhPopupController * _Nonnull popupController) {
        if (alertView.priceTextFeild.text.length <= 0 || [alertView.priceTextFeild.text doubleValue] <= 0) {
            [weakSelf freeCheckAction:weakSelf.freeCheckBtn];
        }
    }];
}

- (IBAction)nextStepAction:(UIButton *)sender {
 
    sender.enabled = NO;
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        sender.enabled = YES;
    });
    
    self.viewModel.info.title = self.circleNameTextFeild.text;
    self.viewModel.info.intro = self.descTextView.text;
//    self.viewModel.info.joinPrice = [self.priceTextFeild.text floatValue];
    
    if (!_checkButton.selected) {
        [MBProgressHUD mh_showTips:@"请同意用户协议！"];
        return ;
    }
    
    if (self.viewModel.info.coverUrl.length <= 0) {
        [MBProgressHUD mh_showTips:@"请选择圈子封面"];
        return;
    }
    
//    if (self.viewModel.info.attrId < 0) {
//        [MBProgressHUD mh_showTips:@"请设置圈子属性"];
//        return;
//    }
    if (self.viewModel.info.title.length <= 0) {
        [MBProgressHUD mh_showTips:@"请设置圈子名称"];
        return;
    }
    
    [[self.viewModel.nextCommand execute:nil] subscribeNext:^(id x) {
//        [MHNotificationCenter postNotificationName:MHReloadFirstPageDataNotification object:nil];
    }];
    
}



- (IBAction)checkAction:(UIButton *) checkButton {
    checkButton.selected = !checkButton.selected;
//    self.nextBtn.enabled = checkButton.selected;
}

-(void) masLayoutSubViews
{
    [self.protocolLable mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.checkButton.mas_right);
        make.right.equalTo(self.view).offset(-20);
        make.centerY.equalTo(self.checkButton.mas_centerY);
        //        make.bottom.eq
        
    }];
}

//-(int)getRandomNumber:(int)from to:(int)to
//{
//     return
//}

//-(UIRectEdge)edgesForExtendedLayout
//{
//    return UIRectEdgeNone;
//}

-(void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];
    self.circleImageView.layer.cornerRadius = self.circleImageView.mh_height / 2;
    self.circleImageView.masksToBounds = YES;
}

-(void)bindViewModel
{
    [super bindViewModel];
    if (self.viewModel.info) {
//        if (self.viewModel.info.intro) {
//              RAC(self.viewModel.info , intro) = [RACSignal merge:@[RACObserve(self.textView, text),self.textView.rac_textSignal]];
//        }
//        RAC(self.viewModel.info , title) = [RACSignal merge:@[RACObserve(self.circleNameTextFeild, text),self.circleNameTextFeild.rac_textSignal]];
        self.circleNameTextFeild.text = self.viewModel.info.title;
        [self.circleImageView yy_setImageWithURL:[NSURL URLWithString:self.viewModel.info.fullCoverUrl] placeholder:MHWebImagePlaceholder()];
    }
    [[self.viewModel.uploadImageCommand.executing
      skip:1]
     subscribeNext:^(NSNumber * showHud) {
         if (showHud.boolValue) {
             [MBProgressHUD mh_showProgressHUD:@"上传中..."];
         }else{
             [MBProgressHUD mh_hideHUD];
         }
     }];

}

-(void) maslayoutSubViews{
//   MHCircleTagView *info = [[MHCircleTagView alloc] initWithTags:self.circleModelArray];
//    __weak __typeof(self)weakSelf = self;
//    info.selectTagBlock = ^(int tagIndex) {
//        weakSelf.viewModel.info.attrId = tagIndex;
//    };
//    [self.view addSubview:info];
//    CGFloat space = 30;
//    CGFloat hSpace = 15;
//    CGFloat w = (MH_SCREEN_WIDTH-(space*5))/4;
//    int rows = ceilf(self.circleModelArray.count/4.0);
//    CGFloat height =  rows*w+(20*rows+1);
//    self.circleTagView = info;
//    self.circleTagView.selectIndex = self.viewModel.info.attrId ;
//    [info mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.metionLable.mas_bottom);
//        make.left.right.equalTo(self.view);
//        make.height.mas_equalTo(@(height));
//    }];
    
    
//    [self.circleNameTextFeild mh_limitMaxLength:MHCircleNmaeMaxTextLength];
//    UITextView *textView = [[UITextView alloc] init];
//    [self.view addSubview:textView];
//    textView.font = MHRegularFont_17;
//    textView.placeholder = @"圈子介绍(选填)";
//    textView.placeholderColor = MH_MAIN_TEXT_COLOR_82;
//    [textView mh_limitMaxLength:MHCircleInfoMaxTextLength];
//    textView.delegate = self;
//    textView.returnKeyType = UIReturnKeyDone;
//    textView.textContainerInset = UIEdgeInsetsMake(14, 16, 22, 16+5);
//    self.textView = textView;
//    [self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(info.mas_bottom).mas_offset(5);
//        make.left.right.equalTo(self.view);
//        make.bottom.equalTo(self.view).mas_offset(-5);;
//    }];
    
//     self.textView.text = self.viewModel.info.intro;
    
    self.descTextView.text = self.viewModel.info.intro;
    
}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
    
    if([text isEqualToString:@"\n"]) {
        [textView resignFirstResponder];
        return NO;
    }
    
    return YES;
}


-(YYLabel *)protocolLable
{
    if(!_protocolLable)
    {
        _protocolLable = [YYLabel new];
        _protocolLable.textAlignment = NSTextAlignmentCenter;
        _protocolLable.textVerticalAlignment = YYTextVerticalAlignmentCenter;
        [_protocolLable sizeToFit];
        _protocolLable.numberOfLines = 0;
        CGFloat  preferWith =   MH_SCREEN_WIDTH -   CGRectGetMaxX(self.checkButton.frame) - 20;
        _protocolLable.preferredMaxLayoutWidth = preferWith;
        //        _protocolLable.lineBreakMode =  yylinb
        //        _protocolLable.backgroundColor = [UIColor colorFromHexString:@"#D9D8D9"];
        NSString *agreeStr =  @"我已经阅读并同意《百唠圈子规则》";
        NSMutableAttributedString *one = [[NSMutableAttributedString alloc] initWithString:agreeStr];
        //        one.yy_underlineStyle = NSUnderlineStyleSingle;
        one.yy_font =  MHRegularFont_12;
        one.yy_color = [UIColor colorFromHexString:@"#8e8e8e"];
        one.yy_lineSpacing = 5;
        
        //        if (!self.viewModel.isFinished) {
        [one yy_setColor:[UIColor colorFromHexString:@"#ff6946"] range:NSMakeRange(8, 8)];
        
        //        }
        NSMutableAttributedString *text = [NSMutableAttributedString new];
        [text appendAttributedString:one];
        //        [text appendAttributedString:[self padding]];
        [self.view addSubview:_protocolLable];
        _protocolLable.attributedText = text;
        @weakify(self);
        _protocolLable.textTapAction = ^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
            YYCache *cache=[YYCache cacheWithName:MHCacheGlobleKey];
            @strongify(self);
            NSArray *h5Links  =  [cache objectForKey:MHH5LinksKey];
            for (MHH5Links *link in h5Links) {
                if ([link.type isEqualToString:@"qzgz"]) {
                    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:link.url]];
                    MHWebViewModel * webViewModel = [[MHWebViewModel alloc] initWithServices:self.viewModel.services params:@{MHViewModelRequestKey:request}];
                    [self.viewModel.services pushViewModel:webViewModel animated:YES];
                    return ;
                }
            }
        };
        //        _protocolLable.hidden = self.viewModel.isFinished;
        //        self.checkButton.hidden = self.viewModel.isFinished;
    }
    return _protocolLable;
}


-(MHInfoImagesScrollView *)imageScrollView
{
    if (!_imageScrollView) {
        MHCoverModel *model = [MHCoverModel new];
        model.fullCoverUrl = @"circle_info_image";
        _imageScrollView = [[MHInfoImagesScrollView alloc] initWithImages:self.fullCoverArray?: @[model]];

//        [self.view addSubview:_imageScrollView];
//        _imageScrollView.hidden = YES;
//        [_imageScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
//           make.edges.equalTo(self.view);
//        }];
        _imageScrollView.frame = self.view.frame;
        __weak __typeof(self)weakSelf = self;
        [_imageScrollView bk_whenTapped:^{
            [weakSelf.zh_popupController dismiss];
//            [weakSelf.imageScrollView removeFromSuperview];
//            weakSelf.imageScrollView = nil;
        }];
        _imageScrollView.tapButtonBlock = ^(MHCoverModel *model) {
            [weakSelf.zh_popupController dismiss];
            if ([model.fullCoverUrl isEqualToString:@"circle_info_image"]) {
                [MHPhotoManager fetchPhotosFromAlbum:self maxImagesCount:1 allowCrop:YES selectedAssets:nil completion:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto, NSArray<NSDictionary *> *infos) {
                     UIImage *uploadImage = [photos lastObject];
                    
                    NSData *imageData = UIImageJPEGRepresentation(uploadImage, 0.5);
                    [[weakSelf.viewModel.uploadImageCommand execute:@[imageData]] subscribeNext:^(MHUploadPicture *pic) {
                        weakSelf.circleImageView.image = uploadImage;
                        weakSelf.viewModel.services.client.swithUrlWithUpload = false;
                        weakSelf.viewModel.info.coverUrl = pic.src;
                        weakSelf.viewModel.info.fullCoverUrl = pic.allSrc;
                    }];
                    
                    
                } cancel:^{
                }];
            }else
            {
                
                [weakSelf.circleImageView yy_setImageWithURL:[NSURL URLWithString:model.fullCoverUrl] placeholder:MHCircleBgPlaceHolder()];
                weakSelf.viewModel.info.coverUrl = model.coverUrl;
                weakSelf.viewModel.info.fullCoverUrl = model.fullCoverUrl;

            }
           
        };
        
    }
    return _imageScrollView;
}

-(void) rightButtonClick{
    
   
//    if (self.viewModel.info.attrId < 0) {
//        [MBProgressHUD mh_showTips:@"请选择圈子属性"];
//        return;
//    }
    
    
    
   
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
